<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <title></title>
    <meta name="renderer" content="webkit">
    <meta name="author" content="中文Lee 360811363@qq.com">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="../../../lib/layui-v2.6.3/css/layui.css" media="all">
    <link rel="stylesheet" href="../../../css/public.css" media="all">
    <!--
    * [LupMisAllowedSync]
    * 本代码为系统自动生成代码，请根据自己业务进行修改;
    * 生成时间 2022-02-20 22:22:22;
    * 版权所有 2020-2022 lizhongwen，并保留所有权利;
    * 说明: 这不是一个自由软件！您只能在不用于商业目的的前提下对程序代码进行修改和使用；不允许对程序代码以任何形式任何目的的再发布;
    * 作者: 中文Lee;
    * 作者主页: http://www.lizhongwen.com;
    * 邮箱: 360811363@qq.com;
    * QQ: 360811363;
    -->
</head>

<body>
    <div class="layuimini-container">
        <div class="layuimini-main">
            <div>
                <form class="layui-form search-box" action="" style="display: none;">
                    <div class="layui-inline">
                        <input type="text" id="file_name" name="file_name" style="width: 120px;" placeholder="文件名" autocomplete="off" class="layui-input">
                    </div>
                    <div class="layui-inline">
                        <button type="submit" class="layui-btn" lay-submit lay-filter="data-search-btn">搜 索</button>
                    </div>
                </form>
            </div>
            <table class="layui-hide" id="data-list" lay-filter="data-list"></table>
        </div>
    </div>
    <script src="../../../js/run.js"></script>

    <script type="text/javascript">
        function openLogsDir(fileName) {
            $("#file_name").val(fileName);
            $("button[type='submit']").click();
        }


        function openLogsFile(fileName) {
            openFrame(fileName, "show.html?file_name=" + fileName, ['100%', '100%']);
        }
        $init(function() {

            pageInit(function(pageInfo, toolbarHtml) {
                var jump = pageInfo.jump;
                var queryUrl = pageInfo.query_url;
                var tableName = pageInfo.table_name;
                var cols = [{
                    type: "checkbox"
                }, {
                    field: "system_serial_number",
                    title: "序号",
                    width: 60,
                    sort: true,
                    align: "center",
                    type: "numbers"
                }, {
                    field: "file_name",
                    title: "名称",
                    sort: true,
                    align: "left"
                }, {
                    field: "ori_file_name",
                    title: "目录名称",
                    sort: true,
                    align: "left"
                }, {
                    field: "file_type",
                    title: "文件类型",
                    sort: true,
                    align: "left"
                }, {
                    field: "file_size",
                    title: "文件大小",
                    sort: true,
                    align: "left"
                }, {
                    field: "last_update",
                    title: "最后修改时间",
                    sort: true,
                    align: "left"
                }];
                loadDataSelf(base_gateway + queryUrl, cols, toolbarHtml);
                // 监听搜索操作
                doSearch();
                //监听操作事件(添加 删除 编辑)
                toolbarTap(function(data, pars, event) {
                    //自定义js Tap回调
                    if (event == 'goBack') {
                        var fileName = $("#file_name").val();
                        if (fileName == "") {
                            layer.msg("已经返回至顶层了，无法继续返回了");
                            return false;
                        }
                        var fileNameArr = fileName.split("/");
                        var backDir = [];
                        for (var i = 0; i < fileNameArr.length - 2; i++) {
                            backDir[i] = fileNameArr[i];
                        }
                        var dir = backDir.join("/");
                        if (dir != "") {
                            dir = dir + "/";
                        }
                        openLogsDir(dir);
                    } else if (event == 'delLogs') {
                        if (data.length == 0) {
                            layer.msg('请至少选择一记录!');
                        } else {
                            if (data.length == 1) {
                                tips = '您选择了<span style="color:green;font-size:28px;">【' + data.length + '】</span>条数据，确定要删除吗？';
                            } else {
                                tips = '您选择了<span style="color:red;font-size:28px;">【' + data.length + '】</span>条数据，确定要删除吗？';
                            }
                            var fileNames = "";
                            for (var i = 0; i < data.length; i++) {
                                fileNames += data[i].ori_file_name + ",";
                            }
                            fileNames = fileNames.substring(0, fileNames.length - 1);
                            layer.confirm(tips, {
                                title: '温馨提示',
                                btn: ['确定', '取消'],
                                icon: 5
                            }, function(index) {
                                var url = base_gateway + "sys/logs/delLogs";
                                request(url, {
                                    file_names: fileNames
                                }, function(ret) {

                                    var code = ret.code;
                                    if (code == 200) {
                                        layer.msg(ret.msg, {
                                            icon: 6
                                        });
                                        table.reload('data-list');
                                    } else {
                                        layer.msg(ret.msg, {
                                            icon: 5
                                        });
                                    }
                                });
                            });
                        }
                    }
                });
            });
        });

        function loadDataSelf(url, cols, toolbar, callback, height = "full-110", page = {
            groups: 5
        }, limit = 20, defaultToolbar = ['filter', 'print']) {
            if (!toolbar) {
                toolbar = false;
            }
            if (toolbar == '<div class="layui-btn-container"></div>') {
                toolbar = false;
            }
            if (height == "full-110") {
                var searchBoxHeight = $(".search-box").height();
                searchBoxHeight = parseFloat(searchBoxHeight);
                // var height = $(window).height() - 60 - searchBoxHeight;
                height = $(window).height() - 22 - searchBoxHeight;

                if (height <= 400) {
                    // height = 400;
                }
            }
            if (isMobile()) {
                // height = "";
            }
            // height = $(window).height()-;
            var accesstoken = localStorage.getItem("accesstoken");
            var accessuid = localStorage.getItem("accessuid");
            layui.table.render({
                elem: '#data-list',
                url: url,
                method: 'post',
                contentType: 'application/json',
                headers: {
                    'accessuid': accessuid,
                    'accesstoken': accesstoken
                },
                toolbar: toolbar,
                cellMinWidth: 80,
                loading: false,
                even: true,
                height: height,
                autoSort: true,
                defaultToolbar: defaultToolbar,
                cols: [cols],
                done: function(res, curr, count) {
                    var code = res.code;
                    if (code != 200) {
                        layer.msg(res.msg);
                        return false;
                    }
                    layui.jquery(".layui-table-tool").css("background", "#f8f8f8");
                },
                error: function(obj, content) {
                    //
                },
                // skin:'row',
                // size: 'sm',
                page: false,
                limit: limit,
                response: {
                    statusCode: 200 //重新规定成功的状态码为 200，table 组件默认为 0
                },
                parseData: function(res) { //将原始数据解析成 table 组件所规定的数据
                    if (callback) {
                        callback(res);
                    }
                    if (res.code == 401) {
                        localStorage.setItem("accesstoken", null);
                        localStorage.setItem("accessuid", null);
                        layer.alert(res.msg, {
                            icon: 1,
                            closeBtn: 0
                        }, function(index) {
                            //关闭弹窗
                            layer.close(index);
                            window.location.href = project_path + "login.html";
                        });
                    } else if (res.code == 403) {
                        layer.msg(res.msg);
                        return false;
                    } else {
                        return {
                            "code": res.code, //解析接口状态
                            "msg": res.msg, //解析提示文本
                            "count": res.data.total || res.data.length || 0, //解析数据长度
                            "data": res.data.rows || res.data || [] //解析数据列表
                        };
                    }

                }
            });
        }
    </script>
</body>

</html>